package com.davidlife.javase.netsocket.tcpdemo;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Proxy;
import java.net.Socket;

public class TcpClient {
    public static void main(String[] args) throws IOException {
        Socket client = new Socket("127.0.0.1", 8888);
        OutputStream os = client.getOutputStream();
        InputStream is = client.getInputStream();

        os.write("你好".getBytes());
        System.out.println("客户端发送了你好，等待响应。。。");

        //接受服务端的响应
        byte[] b = new byte[1024];
        int len = is.read(b);
        if (len != -1) {
            String msg = new String(b, 0, len);
            System.out.println("服务端响应信息为：" + msg);
        }

        is.close();
        os.close();
        client.close();
    }
}
